home *** CD-ROM | disk | FTP | other *** search
- Path: interramp.com!usenet
- From: Barnett@interramp.com (Barnett E. Kurtz)
- Newsgroups: comp.lang.c++
- Subject: Re: cin.get(string) problem
- Date: Mon, 12 Feb 1996 02:14:40 GMT
- Organization: EntroData, Inc.
- Message-ID: <4fm7ti$ls1@usenet6.interramp.com>
- References: <4fk02a$nh@reader2.ix.netcom.com>
- Reply-To: Barnett@interramp.com
- NNTP-Posting-Host: ip167.philadelphia.pa.interramp.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hi Kurt,
-
- You probably should use cin.getline rather than cin.get for that kind
- of task. cin.get leaves the delimiter behind in the input buffer
- (default is '\n') so the next call to cin.get returns a zero length
- string. If you really need to use cin.get, then follow with a int
- dummy = cin.get(); This will cause the leftover delimiter to be
- extracted from the buffer so that you can follow with another
- cin.get(string,sizeof(string));
-
- BTW as far as I know this is the standard behavior for cin.get. It
- works the same way in MS VC++ and BCC++ 4.5, DEC C++, etc.
-
- greinerk@ix.netcom.com (Kurt W. Greiner) wrote:
-
- >Hi all,
- > i was trying some really simple io for a program that just gets
- >values, here is a sample of code
-
- >#include <iostream.h>
-
- >void main(void)
- >{
- > char string[80];
- > cin.get(string,sizeof(string));
- > cin.get(string,sizeof(string));
- >}
-
- >ok, say i want to read in a name on the first cin, i type in "john smith" and
- >the prompt, john gets thrown in to the first and smith the second, i do not
- >even get prompted for the second cin. it does not happen if i type in a string
- >with out spaces. i am using borland c++ 2.0, am i doing something wrong or is
- >there an other way of doing this other than gets(string)?
-
- >kurt
-
- -
- barnett@interramp.com
- -
-
-